# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
_projname=jool
pkgname=jool-tools
# Keep in sync with _ver in community/jool-modules-{rpi,vanilla}!
pkgver=4.1.8
pkgrel=0
pkgdesc="Userspace control tools for SIIT / NAT64 Jool"
url="https://www.jool.mx"
arch="all"
license="GPL-2.0-only"
makedepends="argp-standalone iptables-dev libnl3-dev"
subpackages="
	$pkgname-openrc
	$pkgname-doc
	$pkgname-bash-completion:bashcomp:noarch
	"
source="https://github.com/NICMx/Jool/releases/download/v$pkgver/$_projname-$pkgver.tar.gz
	jool.conf
	jool_siit.conf
	joold.conf
	jool.initd
	joold.initd
	"
builddir="$srcdir/$_projname-$pkgver"

build() {
	# --disable-shared - w/o this option the build fails with:
	#   relocation R_X86_64_PC32 against symbol 'argp_program_version_hook'
	#   can not be used when making a shared object; recompile with -fPIC
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-shared \
		--with-xtables=yes
	make
}

package() {
	make install DESTDIR="$pkgdir"

	install -D -m 0644 "$srcdir"/jool.conf "$pkgdir"/etc/jool/jool.conf
	install -D -m 0644 "$srcdir"/jool_siit.conf "$pkgdir"/etc/jool/jool_siit.conf
	install -D -m 0644 "$srcdir"/joold.conf "$pkgdir"/etc/jool/joold.conf

	install -D -m 0755 "$srcdir"/jool.initd "$pkgdir"/etc/init.d/jool
	ln -s jool "$pkgdir"/etc/init.d/jool_siit
	install -D -m 0755 "$srcdir"/joold.initd "$pkgdir"/etc/init.d/joold
}

bashcomp() {
	pkgdesc="Bash completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"

	mkdir -p "$subpkgdir"/usr/share
	mv "$pkgdir"/usr/share/bash-completion "$subpkgdir"/usr/share/
}

sha512sums="
4fa211c44a8df33648760185629fa6f941f47b092ddfba36c75c58c016343153ac19cb63e28c5171f8027a4e573e5453963c2f80a0417eb7945804eceda43311  jool-4.1.8.tar.gz
4ae4c20fde75a0fdaed1c7c46ab5078297846b0734d31c7053575ff549984617a5486727c98f442125c6abfe8b170cde23ae4c24a4d6ff14b2ce31490bd46633  jool.conf
a48c84c49c24dd6639b86393fa7870b91fa700ba1e561e2440db1f4a94f3393171407a3cc683f4fc7a26a591578ec732dd3f708c1b4c45787a6e7ec038576357  jool_siit.conf
15758922ba83219f7edf34d93d825fcafb354b551a79f9b70e486faebcb154f55a52806aca6f7b9ec0d8277caa64a06a2525829be41c538cb3c678a78112b5e9  joold.conf
2eefae657e75d264838b435be38178cb3fe98f429f2367cf7cd08646c637f4a8ad3e226b4d7f7d460b28b81b8def9a5f5fd2617e2dd1c0c11889775e25951b21  jool.initd
5c9547b2546b0e360b4d1b1bd824edbc533d3b5f469724192ef164a28f8fa243972f54b3e028d9b27ec972fba5d5fc48d87c472333bbc1142a5a64241f1a32e2  joold.initd
"
